package cocom.iplatform.piaoerbai.controller;

import cocom.iplatform.piaoerbai.bean.FileBean;
import cocom.iplatform.piaoerbai.bean.FileBeanPage;
import cocom.iplatform.piaoerbai.bean.ResultBean;
import cocom.iplatform.piaoerbai.constants.BaseConstants;
import cocom.iplatform.piaoerbai.service.FileService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @className: FileController
 * @description: TODO 类描述
 * @author: chensk
 * @date: 2020/12/3
 **/
@RestController
@RequestMapping("file")
public class FileController {
    @Resource
    private FileService fileService;

    @RequestMapping("add")
    public ResultBean addFile(@RequestBody  FileBean fileBean) {
        fileService.addFile(fileBean);
        return new ResultBean(BaseConstants.SUCCESS,"添加成功");
    }

    @RequestMapping("selectByCondition")
    public ResultBean selectByCondition(FileBeanPage fileBean) {
        Integer page=fileBean.getPage();
        Integer size=fileBean.getPageSize();
        int pageP = (page == null || page <= 0) ? 1 : page;
        int sizeP = (size == null || size <= 0) ? 10 : size;
        PageHelper.startPage(pageP,sizeP);
        List<FileBean> fileBeanList= fileService.selectByCondition(fileBean);
        PageInfo<FileBean> pageInfo=new PageInfo<FileBean>(fileBeanList);
        return new ResultBean(BaseConstants.SUCCESS,"查询成功",pageInfo);
    }
}
